﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AD.Model;
using AD.BLL;

public partial class Manager_User_PageData_ReportPoints : WebManagerForm
{
    public List<ReportPointsMod> reports = new List<ReportPointsMod>();
    public int currPageIndex = 1;
    public int MaxSize = 0;
    public int MaxPage = 0;
    public string userName = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        string indexstr = Request.QueryString["pageIndex"];
        string action = Request.QueryString["action"];
        userName = Request.Params["userName"];
        if (string.IsNullOrEmpty(userName))
        {
            userName = "";
        }
        int index;
        int.TryParse(indexstr, out index);
        SetDataBind(userName, "", UtilHepler.PAGE_SIZE, index);
    }

    void SetDataBind(string name, string filter, int pageSize, int index)
    {
        List<UserMod> users = null;
        if (string.IsNullOrEmpty(userName))
            users = UserBLL.QueryFilterToList("");
        else
            users = UserBLL.QueryFilterToList(" Email='" + userName + "'");
        if (users != null)
        {
            foreach (UserMod user in users)
            {
                ReportPointsMod points = new ReportPointsMod();
                string tmpFilter = filter + " and UserId=" + user.AutoID;
                if (string.IsNullOrEmpty(filter))
                    tmpFilter = " Status=1 and UserId=" + user.AutoID;
                points.UserName = user.Email;
                points.BalancePoint = user.BalancePoint;
                List<PayTradeMod> tmps = PayTradeBLL.QueryByPage(tmpFilter, pageSize, index == 0 ? 0 : index - 1, out MaxSize);
                if (tmps != null && tmps.Count > 0)
                {
                    points.MaxExpense = AccountFlowBLL.SumByUserId(user.AutoID);
                    points.RewardPoints = tmps.Sum(tmp => tmp.RewardPoints);
                    points.GiftPoints = tmps.Sum(tmp => tmp.GiftPoints);
                    points.Rechargepoints = tmps.Sum(tmp => tmp.Rechargepoints);
                }
                reports.Add(points);
            }
        }
    }
}